import copy
import cv2
import numpy as np

import torch
import torch.nn.functional as F
import torchvision

from torch import nn
from torchvision.ops import MultiScaleRoIAlign
from typing import List, Tuple, Dict

from my_py_toolkit.file.file_toolkit import *
from torch.optim import Adam
from torch.utils.data import DataLoader, Dataset, TensorDataset
from torchvision.models.detection._utils import overwrite_eps
from torchvision._internally_replaced_utils import load_state_dict_from_url

from torchvision.models.detection.anchor_utils import AnchorGenerator
from torchvision.models.detection.generalized_rcnn import GeneralizedRCNN
from torchvision.models.detection.rpn import RPNHead, RegionProposalNetwork
# from torchvision.models.detection.roi_heads import RoIHeads
from torchvision.models.detection.transform import GeneralizedRCNNTransform
from torchvision.models.detection.backbone_utils import resnet_fpn_backbone, _validate_trainable_layers, mobilenet_backbone
from torchvision.models.detection import _utils as det_utils
from torchvision.models.detection.roi_heads import fastrcnn_loss, maskrcnn_loss, maskrcnn_inference, keypointrcnn_loss, keypointrcnn_inference
from torchvision.ops import boxes as box_ops
from tqdm import tqdm

